package org.jeecg.modules.simulator.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.simulator.jsonot.IndexCd;
import org.jeecg.modules.simulator.jsonot.PasgrPeriod;
import org.jeecg.modules.simulator.mapper.SimulatorIndexCdMapper;
import org.jeecg.modules.simulator.mapper.SimulatorPasgrPeriodMapper;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @program: simulator-b20240918
 * @description:
 * @author: renzhg
 * @create: 2024-12-11 17:21
 **/
@Slf4j
@Primary
@Service
public class QueryPasgrPeriodServiceImpl extends ServiceImpl<SimulatorPasgrPeriodMapper, PasgrPeriod> implements QueryPasgrPeriodService {
    @Resource
    private SimulatorPasgrPeriodMapper sppmaper;
    private SimulatorIndexCdMapper indexcdmapper;

    @Override
    public List<PasgrPeriod> queryPasgrPeriodByIDD(String date, String endTime, String indexType) {

        List<IndexCd> indexlist = indexcdmapper.getFiveTimeIndex();

        Map<String, String> indexmap = indexlist.stream().collect(Collectors.toMap(IndexCd::getStartTmDesc, IndexCd::getStIndexCd));
        Map<String, String> timemap = indexlist.stream().collect(Collectors.toMap(IndexCd::getStIndexCd, IndexCd::getStartTmDesc));


        String endIndex = indexmap.get(endTime);
        List<PasgrPeriod> retlist = sppmaper.findPasgrPeriodByindex(endIndex, indexType, date);
        for (int i = 0; i < retlist.size(); i++) {
            String indextime = timemap.get(retlist.get(i).getIndexCd());
            retlist.get(i).setIndexTime(indextime);


        }


        return retlist;
    }


}
